part of '../controller.dart';

class _SuccessfulResponseDto extends Equatable {
  const _SuccessfulResponseDto._internal({
    required this.appStorePurchasedItemDtos,
    required this.googlePlayPurchasedItemDtos,
    required this.webPurchasedItemDtos,
  });

  final BuiltList<ApiAppStorePurchasedItemDto> appStorePurchasedItemDtos;
  final BuiltList<ApiGooglePlayPurchasedItemDto> googlePlayPurchasedItemDtos;
  final BuiltList<ApiWebPurchasedItemDto> webPurchasedItemDtos;

  @override
  List<Object?> get props {
    return [
      appStorePurchasedItemDtos,
      googlePlayPurchasedItemDtos,
      webPurchasedItemDtos,
    ];
  }

  factory _SuccessfulResponseDto({
    required BuiltList<ApiAppStorePurchasedItem> appStorePurchasedItems,
    required BuiltList<ApiGooglePlayPurchasedItem> googlePlayPurchasedItems,
    required BuiltList<ApiWebPurchasedItem> webPurchasedItems,
  }) {
    final appStorePurchasedItemDtos = appStorePurchasedItems.map((purchasedItem) {
      return ApiAppStorePurchasedItemDtoFactory().fromEntity(purchasedItem);
    }).toBuiltList();

    final googlePlayPurchasedItemDtos = googlePlayPurchasedItems.map((purchasedItem) {
      return ApiGooglePlayPurchasedItemDtoFactory().fromEntity(purchasedItem);
    }).toBuiltList();

    final webPurchasedItemDtos = webPurchasedItems.map((purchasedItem) {
      return ApiWebPurchasedItemDtoFactory().fromEntity(purchasedItem);
    }).toBuiltList();

    return _SuccessfulResponseDto._internal(
      appStorePurchasedItemDtos: appStorePurchasedItemDtos,
      googlePlayPurchasedItemDtos: googlePlayPurchasedItemDtos,
      webPurchasedItemDtos: webPurchasedItemDtos,
    );
  }

  Map<String, dynamic> toJson() {
    final appStorePurchasedItemJsons = appStorePurchasedItemDtos.map((appStorePurchasedItemDto) {
      return appStorePurchasedItemDto.toJson();
    }).toList();

    final googlePlayPurchasedItemJsons =
        googlePlayPurchasedItemDtos.map((googlePlayPurchasedItemDto) {
      return googlePlayPurchasedItemDto.toJson();
    }).toList();

    final webPurchasedItemJsons = webPurchasedItemDtos.map((webPurchasedItemDto) {
      return webPurchasedItemDto.toJson();
    }).toList();

    return {
      'app_store_purchased_items': appStorePurchasedItemJsons,
      'google_play_purchased_items': googlePlayPurchasedItemJsons,
      'web_purchased_items': webPurchasedItemJsons,
    };
  }
}
